package com.cstp.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cstp.entity.Question;
import com.cstp.manage.QuestionManage;
import com.cstp.web.req.QuestionPageReq;
import com.cstp.web.req.QuestionReq;
import com.cstp.web.res.Resp;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author watts
 */
@RestController
public class QuestionController {

    @Resource
    private QuestionManage questionManage;

    @PostMapping("/question/insert")
    public Resp<Boolean> insert(@RequestBody @Valid QuestionReq param) {
        return Resp.ok(questionManage.publish(param));
    }

    @PostMapping("/question/delete/{id}")
    public Resp<Boolean> delete(@PathVariable Long id) {
        return Resp.ok(questionManage.delete(id));
    }

    @PostMapping("/question/detail/{id}")
    public Resp<Question> detail(@PathVariable Long id) {
        return Resp.ok(questionManage.detail(id));
    }

    @PostMapping("/question/update")
    public Resp<Boolean> update(@RequestBody QuestionReq param) {
        return Resp.ok(questionManage.publish(param));
    }

    @PostMapping("/question/list")
    public Resp<IPage<Question>> list(@RequestBody QuestionPageReq param) {
        return Resp.ok(questionManage.list(param));
    }

    @PostMapping("/api/question/random5")
    public Resp<List<Question>> random5() {
        return Resp.ok(questionManage.random5());
    }
}
